<div class="row">
<div class="button-container mb10">
	<?php echo Yii::app()->user->checkAccess('role|create')?CHtml::link('添加角色',$this->createUrl('role/create'),array('class'=>'button')):'';?>
</div>
<table class="table table-bordered table-striped">
	<thead>
		<tr>
			<th style="width: 80px;"><input type="checkbox" class="btn_all" /> 编号</th>
			<th>角色名称</th>
			<th>描述</th>
			<th style="width:200px;">管理操作</th>
		</tr>
	</thead>
	<?php foreach ($model as $v){?>
	<tr>
		<td><input type="checkbox" class="ids" name="ids[]" value="<?php echo $v->role_id;?>" /> <?php echo $v->role_id;?></td>
		<td><?php echo $v->role_name;?></td>
		<td><?php echo $v->description;?></td>
		<td>
			<?php echo Yii::app()->user->checkAccess('role|auth')?CHtml::link('权限设置',$this->createUrl('role/auth',array('id'=>$v->role_id)),array('class'=>'setpower','action_list'=>$v->action_list)):'';?>
			<?php echo Yii::app()->user->checkAccess('role|update')?CHtml::link('编辑',$this->createUrl('role/update',array('id'=>$v->role_id))):'';?>
			<?php echo Yii::app()->user->checkAccess('role|delete') && $v->role_id!=1?CHtml::link('删除','javascript:void(0);',array('class'=>'delete','url'=>$this->createUrl('role/delete',array('id'=>$v->role_id)))):'';?>
		</td>
	</tr>
	<?php }?>
</table>
<div class="table-bottom-operate">
    <div class="inline pull-left table-operate">
        <?php echo Yii::app()->user->checkAccess('role|deleteall')?CHtml::link('批量删除','javascript:void(0);',array('class'=>'button button-primary deleteall','url'=>$this->createUrl('role/deleteall'))):'';?>
    </div>
    <div class="inline pull-right page">
        <?php $this->widget('LinkPager',array('pages' => $pages)); ?>
    </div>
</div>
</div>
<script>
$('.setpower').click(function(){
	var href = $(this).attr('href');
	var action_list = $(this).attr('action_list');
	$.getJSON(href,function(sdata){
		 art.dialog({
		    content:'<div id="all-menu" style="width:800px;height:600px;"></div><div><input type="hidden" id="menu_ids" value="'+action_list+'"><div>',
		    title:'权限设置',
		    width:'800px',
		    height:'600px',
		    padding:'0px',
		    ok: function () {
			    var menu_ids = $('#menu_ids').val();
			    $.getJSON(href,{menu_ids:menu_ids},function(returnData){
					if(returnData.err==0){
						parent.jsshow('权限设置成功','','success');
						window.location.reload();
					}else{
						parent.jsshow('权限设置失败','','error');
					}
				});
		        return true;
		    },
		    cancelVal: '关闭',
		    cancel: true
		 });
		 BUI.use('<?php echo $this->module->assetsUrl .'/js/tree';?>',function (Tree) {
			      //由于这个树，不显示根节点，所以可以不指定根节点
			      var tree = new Tree.TreeList({
			        render : '#all-menu',
			        width : 800,
			        height : 600,
			        nodes : sdata,
			        //dirSelectable:false,
			        checkType: 'custom', //checkType:勾选模式，提供了4中，all,onlyLeaf,none,custom
			        //cascadeCheckd : false, 
			        showLine : true //显示连接线
			      });
			      tree.render();
			      tree.on('itemclick',function(ev){
			          var checkedNodes = tree.getCheckedNodes();
			          var arr=new Array();
			          BUI.each(checkedNodes,function(node){
			        	  arr.push(node.id);
			          });
			          $('#menu_ids').val(arr.join(','));
			      });
		    });
	});
	return false;
 });
</script>